package Execise;

import java.util.Scanner;

public class cs2LianJin {
        static double avg,aa;
        public static void main(String[] args) {
            getAvg();
        }
        public static double sum(double[] adv) {
            double sum = 0;
            for (int i = 0; i < adv.length; i++) {
                sum += adv[i];
            }
            return sum;
        }
        public static void getAvg() {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入主料个数");
            int n = sc.nextInt();
            double[] adv = new double[n];
            for (int i = 0; i < n;) {
                System.out.println("请输入第" + (i + 1) + "个主料磨损");
                aa = sc.nextDouble();
                if (aa<1 && aa>0) {
                    adv[i] = aa;
                    i++;
                } else {
                    System.out.println("超出了范围,继续录入,当前的位置为" + (i + 1));
                }
            }
            System.out.println("请输入主料最高磨损");
            double a1 = sc.nextDouble();
            System.out.println("请输入主料最低磨损");
            double a2 = sc.nextDouble();
            System.out.println("请输入产物的最高磨损");
            double b1 = sc.nextDouble();
            System.out.println("请输入产物的最低磨损");
            double b2 = sc.nextDouble();
            System.out.println("输入需要卡的磨损");
            double c = sc.nextDouble();
            // 计算主料平均磨损：总和（通过sum方法）/个数n
            double avgAdv = sum(adv) / n;
            // 使用平均磨损参与计算
            avg = (c / (b1 - b2) * 10 - n * ( avgAdv / (a1 - a2))) / (10 - n);
            System.out.println("辅料平均磨损:" + avg);
            sc.close();
        }
}
